package com.object;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ObjSerializable implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	public int i;
	public static void main(String[] args) throws Exception {
		ObjSerializable x = new ObjSerializable();
		x.i = 1000;
		
		ByteArrayOutputStream bytecache = new ByteArrayOutputStream();
		ObjectOutputStream out = new ObjectOutputStream(bytecache);
		out.writeObject(x);
		
		
		byte[] buf = bytecache.toByteArray();
		ByteArrayInputStream bytecachein = new ByteArrayInputStream(buf);
		ObjectInputStream in = new ObjectInputStream(bytecachein);
		ObjSerializable x2 = (ObjSerializable) in.readObject();
		
		System.out.println(x2.i);
	}
}
